package com.vanzo.talkie;

import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;

import com.vanzo.bean.Master;
import com.vanzo.encryption.Encryption;
import com.vanzo.encryption.R;
import com.vanzo.ui.BaseActivity;
import com.vanzo.ui.HomeActivity;


/**
 * Created by tisen on 2017/12/25.
 */

public class LoadActivity extends BaseActivity implements View.OnClickListener {

    private boolean isLoading;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_loading);
//        findViewById(R.id.power_tip).setVisibility(View.INVISIBLE);

    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if (hasFocus && Build.VERSION.SDK_INT >= 19) {
            View decorView = getWindow().getDecorView();
            decorView.setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
                            View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
                            View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
//                            View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
//                            View.SYSTEM_UI_FLAG_FULLSCREEN |
                            View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
        }
    }

    @Override
    public boolean isShowTip() {
        return false;
    }

    @Override
    public void onClick(View v) {
        Master master = new Master();
        switch (v.getId()) {
            case R.id.loading_master:
                master.setIsMaster(true);
                master.setGk(Encryption.getGroupKey());
                break;
            case R.id.loading_follower:
                master.setIsMaster(false);
                break;
        }
        tpplication.updateMaster(master);
        toHomeActivity();
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (tpplication.getMaster() == null) {
            initMaster();
            isLoading = true;
            toHomeActivity();
            findViewById(R.id.loading_master).setOnClickListener(this);
            findViewById(R.id.loading_follower).setOnClickListener(this);
        } else {
            toHomeActivity();
            isLoading = true;
        }
    }

    private void initMaster() {
        Master master = new Master();
        master.setIsMaster(true);
        master.setGk(Encryption.getGroupKey());
        tpplication.updateMaster(master);
        toHomeActivity();
    }

    private void toHomeActivity() {
        finish();
        startActivity(new Intent(this, HomeActivity.class));
    }
}
